package hk.cic.demointegrationapp.log;

//import android.app.Service;
//import android.content.Intent;
//import android.os.IBinder;


import android.app.Service;
import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;

import com.cily.utils.log.L;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Locale;

import org.json.JSONObject;
import org.json.JSONException;

import hk.cic.cwrs.bio.integration.IBioTemplateService;
import hk.cic.cwrs.bio.integration.log.IBioService;
import hk.cic.cwrs.driver.CICdevice;
import hk.cic.cwrs.bio.integration.BiometricDeviceService;

public class BiometricLogService extends Service {
    public BiometricLogService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    private final IBioService.Stub mBinder = new IBioService.Stub() {

        public void ResultLog(String logDetail) throws RemoteException {
            logDetail = "1234567890";
            L.e("TAG", "IBioService logDetail：" + logDetail);
        }

        public void WriteTemplate(String sessionId, String template) throws RemoteException {
        }

        //       public String testLog(String name){
        //           String str= name + "_OK";
//         return str;
//        }
    };
}


//-----------------------verifyTemplate -------------------------------------
//            String strReturn =  "{\"SessionId\":\""+sessionId+"\", \"CWRNo\": \""+CWRNo+"\", \"Result\":\"1\", \"Datetime\": \""+sdf.format(new java.util.Date())+"\"}";
//            String logmsg = sdf2.format(new java.util.Date())+" sessionId:"+sessionId+", CWRNo:"+CWRNo+", template:"+template+", writeDate:"+writeDate+", writeId:"+writerId+", SerialNo:"+serialNo+", greenCardExpire: "+greenCardExpire;
//            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH);
//            SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.ENGLISH);
//--------------------------ResultLog----------------------------------------
//            String strMsg="sessionId:"+sessionId+", CWRNo:"+CWRNo+", Result:"+Result+", Datetime:"+Datetime;
//            String strParams ="{\"SessionId\":\""+sessionId+"\", \"CWRNo\": \""+CWRNo+"\", \"Result\":\"1\", \"Datetime\": \""+sdf.format(new java.util.Date())+"\"}";

//---------------------------------------------------------------------------



  /*  private static boolean bCICLog = false;

    static {
        try {
            File libFile = new File("/system/lib/iinterface.so");
            if (libFile.exists()) {
                System.load("/system/lib/iinterface.so");
                Log.d("TAG_LOG", "System.load");
                bCICLog = true;
            } else
                Log.d("TAG_LOG", "no loadLibrary");
        } catch (Exception e) {
            Log.d("TAG_LOG", "Cannot Load iinterface.so - Probably non-CIC Device");
        }

    }

    private void ComPort(){
        int i = 0;
        if(!bCICLog)
            Log.d("TAG_LOG","ReceiveRS232() Non CIC Device - RS232 signal not receive");
        else{
            i=CICdevice.OpenRS232(0);
            if(i==0){
                i=CICdevice.ReceiveRS232(strReceive);
                if(i==0){
                     Log.d("TAG_LOG","RS232 Receive");
                }
                else{
                     Log.d("TAG_LOG","Cant RS232 Receive");
                }
            }
            else{
                Log.d("TAG_LOG","Cant OpenRS232");
            }
        }

    }*/
/*

//        public void WriteTemplate(String sessionId, String template) throws RemoteException {
//        }

import org.json.JSONObject;
import org.json.JSONException;

    private static final String JSON_STRING =
        "{\"person\":{\"name\":\"A\",\"age\":30,\"children\":[{\"name\":\"B\",\"age\":5}," + "\"name\":\"C\",\"age\":7},{\"name\":\"D\",\"age\":9}]}}";

        try {
            JSONObject person = (new JSONObject(JSON_STRING)).getJSONObject("person");
            String name = person.getString("name");
            line1.setText("This person's name is " + name);
            line2.setText(name + " is " + person.getInt("age") + " years old.");
            line3.setText(name + " has " + person.getJSONArray("children").length()
                + " children.");
        } catch (JSONException e) {
            e.printStackTrace();
        }
 */